package com.hua.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

public class CityDatasource {
	public CityDatasource() {

	}

	/**
	 * json字符串的数据源
	 * 
	 * @return
	 */
	public static List<String> getCityList() {
		List<String> list = new ArrayList<String>();
		list.add("北京");
		list.add("上海");
		list.add("山东");
		list.add("河北");
		list.add("山东");
		return list;
	}

	/**
	 * xml字符串的数据源生成
	 * 
	 * @return
	 */
	public static String getCityListForXml() {
		try {
			// 通过反射获得类的加载器 然后将文件加载
			InputStream inputStrem = CityDatasource.class.getClassLoader().getResourceAsStream("com/hua/utils/citys.xml");
			BufferedReader buffer = new BufferedReader(new InputStreamReader(inputStrem, "utf-8"));
			String values = "";
			StringBuilder sb = new StringBuilder();
			try {
				while ((values = buffer.readLine()) != null) {
					sb.append(values);
				}
				return sb.toString();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (buffer != null) {
					try {
						buffer.close();
					} catch (Exception e2) {
						e2.printStackTrace();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
}
